package com.sondon.mayi.adapter;

import java.util.ArrayList;

import org.androidannotations.annotations.EBean;
import org.androidannotations.annotations.RootContext;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.sondon.mayi.entity.Cart;

/**
 * @Project : Fruit
 * @Package : com.sondon.mayi.adapter
 * @Class : CartListAdapter.java
 * @Company 广州讯动网络科技有限公司
 * @Author : 蔡文锋
 * @DateTime：2015-6-18 下午1:34:43
 * @Blog：http://blog.csdn.net/caiwenfeng_for_23
 * @Description : { 购物车列表适配器 }
 */
@EBean
public class CartListAdapter extends BaseAdapter {
	@RootContext
	Context context;
	ArrayList<Cart> datas=new ArrayList<Cart>();
	private CartList_ItemChanageListener listener=null;
	private boolean isAllChecked=false;
	
	//设置购物车数据
	public void SetData(ArrayList<Cart> datas){
		this.datas.clear();
		if(datas !=null&&datas.size()>0){
			this.datas.addAll(datas);
		}
		notifyDataSetChanged();
	}
	//获取购物车数据
	public ArrayList<Cart> GetData(){
		return datas;
	}
	
	//设置购物车列表Num改变监听事件
	public void SetListener(CartList_ItemChanageListener listener){
		if(listener!=null){
			this.listener=listener;
		}
		notifyDataSetChanged();
	}
	
	//设置全选
	public void SetAllChecked(boolean isAllChecked){
		this.isAllChecked=isAllChecked;
		notifyDataSetChanged();
	}
	
	@Override
	public int getCount() {
		return this.datas.size();
	}

	@Override
	public Object getItem(int position) {
		return this.datas.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		CartList_Item item = null;
		if (convertView == null) {
			item = CartList_Item_.build(context);
		} else {
			item = (CartList_Item) convertView;
		}
		item.bindData(this.datas.get(position),this.listener,this.isAllChecked,position);
		return item;
	}

}
